
package game;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import boundaryToMatador.GUI;
import fields.*;

public class Game {
	
	/**
	 * main method
	 * 
	 * @param args command line arguments
	 * 
	 * @throws IOException
	 * 
	 * @return void
	 */
	public static void main(String[] args) throws IOException {
		playGame();
	}
	
	/**
	 * game cycle
	 * 
	 * @throws IOException
	 * 
	 * @return void
	 */
	public static void playGame() throws IOException {
		while (true) {
			//init and launch GUI
			GUIout out = new GUIout();
			out.startGUI();
			
			//Select language and load translations from file
			String lang = "eng";
			String langSelected = GUI.getUserButtonPressed("Choose language", "ENG", "DNK");
			if(langSelected == "DNK") {
				lang="dnk";
			}
			HashMap<String, String> translations = generateTranslations(lang);
			
			//init game objects
			Cup cup = new Cup();
			Gameboard board = new Gameboard();
			GUIin in = new GUIin(translations);
			Chanceliste liste = new Chanceliste(translations);
			out.setTranslations(translations);
			
			out.welcomeText();
			int activeplayers = in.getNumberOfPlayers(); // defines  number of active players method from GUIin
			Player[] players = new Player[activeplayers]; //  object array, length equals tonumber of active players
			players = in.addPlayers(players);
			int i=0;
			while (true) { 
				//players turn
				playTurn(players[i], cup, board, out, in, liste, players, translations);
				//post turn check if game ended or not
				if (players[i].hasLost() && players[i].isActive()) { 
					out.playerHasLost(players[i].getName(), players[i].getField());
					players[i].bankrupt();
					activeplayers--;
				}
				i++;
				if (i==players.length) {
					i=0;
				}
				
				if (activeplayers==1) {
					break;
				}
			}
	
			for (i=0; i<players.length; i++) {
				if (players[i].isActive()) {
					break;
				}
			}
			out.playerHasWon(players[i].getName());
			
			if (!in.playAgain()) {
				break;
			} else {
				out.closeGUI();
			}
		}
		GUI.close();
	}
	
	/**
	 * Load translation file. File format KEY:VALUE. File path <lang>.lng
	 * 
	 * @param lang language to load
	 * 
	 * @return HashMap<String,String> - HashMap key:value with translations
	 * @throws IOException
	 */
	private static HashMap<String, String> generateTranslations(String lang) throws IOException {
		HashMap<String, String> translations = new HashMap<String, String>(); // new object
		String path = lang+".lng";
		//File reader
		BufferedReader in = new BufferedReader(new FileReader(path));
		String s;
		String key;
		String value;
		//Reading file line by line
		while((s = in.readLine()) != null) {
			s=s.trim();			// method of class String for variable s
			//if empty string ignore line
			if (s.compareTo("") == 0) {
				continue;
			}
			//delimiter position in a row
			int index = s.indexOf(':');
			//if no delimiter found - ignore row
			if (index!=-1) {
				//Before delimiter - KEY
				key = s.substring(0,index);
				//After delimiter - VALUE
				value = s.substring(index+1);
				//add key-value pair to hashmap
				translations.put(key,value);
			}
		}
		//close filereader
		in.close();
		return translations;
	}


	public static void playTurn(Player player, Cup cup, Gameboard board, GUIout out, GUIin in, Chanceliste liste, Player[] players, HashMap<String, String> translations) {
		GUI.getUserButtonPressed(player.getName()+translations.get("GAME_TURN"), "OK");
		//player in jail - take actions available in jail
		if (player.inJail) {
			jailAction(player, cup, out, board, translations);
		}
		//player not in jail, and player is active - normal move
		if ((player.isActive()) && (player.inJail) == false) {
			rollAndMoveAction(player, cup, out, board, in, liste, players, translations);
		}
		
		//player is able to unmortgage properties - unmortgage action
		int[] mortgagedProperties = player.getMortgagedProperties();
		if (mortgagedProperties.length>0) {
			unmortgateAction(mortgagedProperties, player, board, out, translations);
		}
		
		//player is able to build houses - build action
		int[] streetsAvailableForBuilding = player.getStreetsPlayerCanBuildIn(board);
		if (streetsAvailableForBuilding.length>0) {
			buildAction(streetsAvailableForBuilding, player, board, out, translations);
		}
	}
	
	private static void unmortgateAction(int[] mortgagedProperties, Player player, Gameboard board, GUIout out, HashMap<String,String> translations) {
		String finishTxt = translations.get("GAME_FINISH");
		String yesTxt = translations.get("GAME_YES");
		String noTxt = translations.get("GAME_NO");
		//Player chooses if he want to unmortgage properties
		if (GUI.getUserButtonPressed(translations.get("GAME_DO_YOU_WANT_TO_UNMORTGAGE"), yesTxt, noTxt).compareTo(yesTxt) == 0) {
			while (true) {
				//Get mortgaged properties names
				String[] propertyNames = new String[mortgagedProperties.length+1];
				for(int i=0; i<mortgagedProperties.length; i++) {
					Field field = board.getField(mortgagedProperties[i]);
					propertyNames[i] = field.getName();
				}
				// add "finish" button
				propertyNames[mortgagedProperties.length] = finishTxt;
				String selected = GUI.getUserButtonPressed(translations.get("GAME_SELECT_UNMORTGAGE_PROPERTY"), propertyNames);
				//player pressed "Finish" - end cycle
				if (selected.compareTo(finishTxt) == 0) {
					break;
				}
				int selectedFieldNr = board.getFieldNumberByName(selected);
				Field field = board.getField(selectedFieldNr);
				//get unmortgag value
				int value = field.getBuyOutFromMortagePrice();
				//if enough money - unmortgage
				if (player.haveAmount(value)) {
					field.buyOutFromMortage();
					player.withdraw(value);
				} else {
					GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY"), "OK");
				}
				out.setBalance(player.getName(), player.getAccount());
				//get properties available to unmortgage
				mortgagedProperties = player.getMortgagedProperties();
			}
		}
	}

	/**
	 * Houses build action
	 * 
	 * @param streetsAvailableForBuilding
	 * @param player
	 * @param board
	 * @param out
	 * @param translations
	 */

	private static void buildAction(int[] streetsAvailableForBuilding, Player player, Gameboard board, GUIout out, HashMap<String,String> translations) {
		String yesTxt = translations.get("GAME_YES");
		String noTxt = translations.get("GAME_NO");
		if (GUI.getUserButtonPressed(player.getName()+"! "+translations.get("GAME_DO_YOU_WANT_TO_BUILD"), yesTxt, noTxt).compareTo("Yes") == 0) {
			String finishTxt = "Finish";
			while (true) {
				//Get properties names
				String[] propertyNames = new String[streetsAvailableForBuilding.length+1];
				for(int i=0; i<streetsAvailableForBuilding.length; i++) {
					Field field = board.getField(streetsAvailableForBuilding[i]);
					propertyNames[i] = field.getName();
				}
				//add "Finish" button
				propertyNames[streetsAvailableForBuilding.length] = finishTxt;
				String selected = GUI.getUserButtonPressed(translations.get("GAME_WHERE_TO_BUILD"), propertyNames);
				//player pressed "Finish" - end cycle
				if (selected.compareTo(finishTxt) == 0) {
					break;
				}
				int selectedFieldNr = board.getFieldNumberByName(selected);
				Field field = board.getField(selectedFieldNr);
				//get build cost
				int buildCost = field.getHouseCost();
				if (player.haveAmount(buildCost)) {
					field.build();
					player.withdraw(buildCost);
				} else {
					GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY"), "OK");
				}
				out.setBalance(player.getName(), player.getAccount());
				//get street on which player can build
				streetsAvailableForBuilding = player.getStreetsPlayerCanBuildIn(board);
			}
		}
	}


	private static void rollAndMoveAction(Player player, Cup cup, GUIout out, Gameboard board, GUIin in, Chanceliste liste, Player[] players, HashMap<String, String> translations) {
		//field on which player stands before move
		int initialField = player.getField();
		out.turnText(player.getName());
		//roll dices
		cup.rollDices();
		int[] dices = cup.getArray();
		boolean isDouble = (dices[0]==dices[1]);
		out.setDices(dices);
		out.removeCar(player.getField(), player.getName());
		if (player.isPrevious2RollsDouble() && isDouble) { //3 doubles - GOTO jail
			GUI.showMessage(translations.get("GAME_3_DOUBLES_IN_A_ROW"));
			player.moveToField(11);
			player.inJail = true;
		} else {
			//move player
			player.move(cup.getRoll());
			//if "Start" is passed add bonus
			if (initialField + cup.getRoll() > 40) {
				out.landOnRefuge(player.getName());
				player.deposit(board.getField(1).getBonus());
				out.setBalance(player.getName(), player.getAccount());
			}
		}
		player.setPrevious2RollsDouble(isDouble);
		out.setCar(player.getField(), player.getName());
		fieldAction(player, board, in, out, cup, liste, players, initialField,translations);
	}


	private static void fieldAction(Player player, Gameboard board, GUIin in, GUIout out, Cup cup, Chanceliste liste, Player[] players, int initialField, HashMap<String, String> translations) {
		int playerfield = player.getField();
		//switch field type
		switch (board.getField(playerfield).getFieldValue()) {
		case 1://Territory. 
			//Not owned - available to buy
			if (board.getField(playerfield).isNotOwned()) {
				if (in.yesOrNo(player.haveAmount(board.getField(playerfield).getPrice()), player.getName(), board.getField(playerfield).getName())) {
					player.setChoice(1);
					board.getField(playerfield).landOnField(player);
					out.setBalance(player.getName(), player.getAccount());
					GUI.setOwner(playerfield, player.getName());
				}
			} else { // Hvis den er ejet, betales rent.
				//if player is not owner of this field
				if (!(board.getField(playerfield).isOwner(player))) {
					//and if it is not motrgaged
					if (!board.getField(playerfield).getIsMortaged()) {
						//Pay rent
						out.landOnElsesField(board.getField(playerfield).getRent());
						while (!player.haveAmount(board.getField(playerfield).getRent())) {
							if (player.canMortgageProperty() || player.canSellHouses()) {
								GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
								sellOrMortgagePropertyAction(player, board,translations);
							} else {
								break;
							}
						}
						board.getField(playerfield).landOnField(player);
						out.setBalance(player.getName(), player.getAccount());
						Player fieldOwner = board.getField(playerfield).getOwnerObject();
						out.setBalance(fieldOwner.getName(), fieldOwner.getAccount());
					} else {
						out.landOnMortgagedField();
					}
				} else {
					out.landAsOwner();
				}
			}
		break;
			
		case 2: //LaborCamp. - See Territory
			if (board.getField(playerfield).isNotOwned()) {
				if (in.yesOrNo(player.haveAmount(board.getField(playerfield).getPrice()), player.getName(), board.getField(playerfield).getName())) {
					player.setChoice(1);
					board.getField(playerfield).landOnField(player);
					out.setBalance(player.getName(), player.getAccount());
					GUI.setOwner(playerfield, player.getName());
				}
			} else {
				if (!(board.getField(playerfield).isOwner(player))) {
					if (!board.getField(playerfield).getIsMortaged()) {
						out.landOnLabor(board.getField(playerfield).getName());
						cup.rollDices();
						player.setChoice(cup.getRoll());
						out.setDices(cup.getArray());
						board.getField(playerfield).setRent(player.getChoice());
						int rent = board.getField(playerfield).getRent();
						GUI.getUserButtonPressed(translations.get("GAME_HAVE_TO_PAY")+" "+rent+" DKK", "OK");
						while (!player.haveAmount(rent)) {
							if (player.canMortgageProperty() || player.canSellHouses()) {
								GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
								sellOrMortgagePropertyAction(player, board, translations);
							} else {
								break;
							}
						}
						board.getField(playerfield).landOnField(player);
						out.setBalance(player.getName(), player.getAccount());
						Player fieldOwner = board.getField(playerfield).getOwnerObject();
						out.setBalance(fieldOwner.getName(), fieldOwner.getAccount());
					} else {
						out.landOnMortgagedField();
					}
				} else {
					out.landAsOwner();
				}
				
			}
		break;
		
		case 3: //Fleet. - see territory
			if (board.getField(playerfield).isNotOwned()) {
				if (in.yesOrNo(player.haveAmount(board.getField(playerfield).getPrice()), player.getName(), board.getField(playerfield).getName())) {
					player.setChoice(1);
					board.getField(playerfield).landOnField(player);
					out.setBalance(player.getName(), player.getAccount());
					GUI.setOwner(playerfield, player.getName());
				}
			} else {
				if (!(board.getField(playerfield).isOwner(player))) {
					if (!board.getField(playerfield).getIsMortaged()) {
						out.landOnField(board.getField(playerfield).getName());
						out.landOnElsesField(board.getField(playerfield).getRent());
						while (!player.haveAmount(board.getField(playerfield).getRent())) {
							if (player.canMortgageProperty() || player.canSellHouses()) {
								GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
								sellOrMortgagePropertyAction(player, board, translations);
							} else {
								break;
							}
						}
						board.getField(playerfield).landOnField(player);
						out.setBalance(player.getName(), player.getAccount());
						Player fieldOwner = board.getField(playerfield).getOwnerObject();
						out.setBalance(fieldOwner.getName(), fieldOwner.getAccount());
					} else {
						out.landOnMortgagedField();
					}
				} else {
					out.landAsOwner();
				}
			}
		break;
		
		case 4: //TAX 
			out.landOnTax();
			if (board.getField(playerfield).getNumber()==4) { //Hvis feltnummeret er 16 betales der bare fastbel�b.
				if(GUI.getUserButtonPressed(translations.get("GAME_PAY_TAX"), "200", "10%") == "200") {
					player.setChoice(1);
					board.getField(playerfield).landOnField(player);
					out.setBalance(player.getName(), player.getAccount());
				} 
				else {
						player.setChoice(2);
						board.getField(playerfield).landOnField(player);
						out.setBalance(player.getName(), player.getAccount());
					}
			} else if (board.getField(playerfield).getNumber()==38) {
				player.setChoice(1);
				board.getField(playerfield).landOnField(player);
				out.setBalance(player.getName(), player.getAccount());
			}
		break;
		
		case 5: // Refuge - "Start" field excluded (another logic)
			if (playerfield == 21) {
				GUI.getUserButtonPressed(player.getName()+", "+translations.get("GAME_500DKK_BONUS"), "OK");
				board.getField(21).landOnField(player);
				out.setBalance(player.getName(), player.getAccount());
			}
		break;
			
		case 6: //Chance 
			out.landOnChance();
			board.getField(playerfield).landOnField(player);
			while (true) {
				//pick card
				liste.pickCard();
				int cardnumber = liste.getcardFromDeck().getchancenumber(); // gets card
				int chancebonus = liste.getcardFromDeck().getchancebonus();
				String message = liste.getcardFromDeck().toString();
				if (cardnumber==2) { //jail escape card
					out.hasFreedom(); // gives a message
					player.addJailEscapeCard(); //save card
					break;
				} else if (cardnumber==6 ) { //goto jail
					out.GotoJail();
					board.getField(playerfield).landOnField(player);
					out.removeCar(player.getField(), player.getName());
					player.moveToField(11);
					playerfield=player.getField();
					out.setCar(playerfield, player.getName());
					player.inJail = true;
					out.testMessage(translations.get("GAME_YOU_STUCK"));
					break;
				} else if (cardnumber==11 ) { //GO back
					out.goBack();
					board.getField(playerfield).landOnField(player);
					out.removeCar(player.getField(), player.getName());
					player.moveToField(initialField);
					playerfield=player.getField();
					out.setCar(playerfield, player.getName());
					break;
				} else if (cardnumber==13 ) { //each player pays 10 to current player
					out.testMessage(message);
					for (int playerNr=0; playerNr<players.length; playerNr++) {
						if (player.getName().compareTo(players[playerNr].getName()) != 0) {
							players[playerNr].withdraw(10);
							out.setBalance(players[playerNr].getName(), players[playerNr].getAccount()); //change accounts
						}
					}
					player.deposit(10*(players.length-1));
					out.setBalance(player.getName(), player.getAccount()); //change accounts
					break;
				} else if (cardnumber==14 ) { // pay 10 and pick another chance card
					out.testMessage(message);
					while (!player.haveAmount(10)) {
						if (player.canMortgageProperty() || player.canSellHouses()) {
							GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
							sellOrMortgagePropertyAction(player, board, translations);
						} else {
							break;
						}
					}
					player.withdraw(10);
					out.setBalance(player.getName(), player.getAccount()); //change account
					if (player.getAccount() == 0) {
						break;
					}
				} else { //other chance - get bonus or pay
					if (chancebonus>0) {
						player.deposit(chancebonus);
					} else {
						while (!player.haveAmount(chancebonus)) {
							if (player.canMortgageProperty() || player.canSellHouses()) {
								GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
								sellOrMortgagePropertyAction(player, board, translations);
							} else {
								break;
							}
						}
						player.withdraw(chancebonus);
					}
					out.setBalance(player.getName(), player.getAccount()); //adds amount from the list
					out.testMessage(message);
					break;
				}
			}
			break;
		case 7://GOTO jail
			out.landOnJail();
			board.getField(playerfield).landOnField(player);
			out.removeCar(player.getField(), player.getName());
			player.move(20);
			playerfield=player.getField();
			out.setCar(playerfield, player.getName());
			player.inJail = true;
			//player.setActive(false);
			out.testMessage(translations.get("GAME_YOU_STUCK"));
			break;	
		}
	}

/**
 * Jail action
 * @param player
 * @param cup
 * @param out
 * @param board
 * @param translations
 */
	private static void jailAction(Player player, Cup cup, GUIout out, Gameboard board, HashMap<String, String> translations) {
		String yesTxt = translations.get("GAME_YES");
		String noTxt = translations.get("GAME_NO");
		String freeNow = translations.get("GAME_FREE_NOW");
		String paidFine = translations.get("GAME_PAID_FINE");
		boolean playerFailedToRollDouble = false;
		boolean playerRefusedToRollDouble = false;
		boolean playerHaveEscapeCard = player.getJailEscapeCardCount()>0;
		boolean playerMustLeaveJail = player.getRoundsInJail()>=3;
		System.out.println(player.getRoundsInJail());
		if (playerMustLeaveJail) {//must leave jail (3 rounds in jail passed)
			if (GUI.getUserButtonPressed(translations.get("GAME_TRY_ROLL_DOUBLE"), yesTxt, noTxt).compareTo(yesTxt)==0) { //try to roll double
				playerFailedToRollDouble = true;
				cup.rollDices();
				int[] dices = cup.getArray();
				boolean isDouble = (dices[0]==dices[1]);
				out.setDices(dices);
				if (isDouble) {
					player.leaveJail();
					GUI.showMessage(freeNow);
					playerFailedToRollDouble = false;
				}
			} else {
				playerFailedToRollDouble = false;
				playerRefusedToRollDouble = true;
			}
			
			if (playerFailedToRollDouble || playerRefusedToRollDouble) { // if player failed to roll double or refused to roll - he must pay or use card
				if (playerHaveEscapeCard) { //player have escape card - he can use it
					if (GUI.getUserButtonPressed(translations.get("GAME_ESCAPE_CARD_OR_PAY"), translations.get("GAME_CARD"), translations.get("GAME_PAY")) == translations.get("GAME_CARD")) {
						GUI.showMessage(freeNow);
						player.leaveJailUsingCard();
					} else { // must pay
						while(!player.haveAmount(50)) {
							GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), "OK");
							if (player.canSellHouses() || player.canMortgageProperty()) {
								sellOrMortgagePropertyAction(player, board, translations);
							} else {
								break;
							}
						}
						GUI.showMessage(paidFine+" "+freeNow);
						player.leaveJailUsingFine();
					}
				} else {
					GUI.showMessage(paidFine+" "+freeNow);
					player.leaveJailUsingFine();
				}
			}
		} else {//can stay in jail
			if (GUI.getUserButtonPressed(translations.get("GAME_TRY_ROLL_DOUBLE"), yesTxt, noTxt).compareTo(yesTxt)==0) { //try to roll double
				playerRefusedToRollDouble = false;
				playerFailedToRollDouble = true;
				cup.rollDices();
				int[] dices = cup.getArray();
				boolean isDouble = (dices[0]==dices[1]);
				out.setDices(dices);
				if (isDouble) {
					player.leaveJail();
					GUI.showMessage(freeNow);
					playerFailedToRollDouble = false;
				}
			} else {
				playerRefusedToRollDouble = true;
				playerFailedToRollDouble = false;
			}
			
			if (playerFailedToRollDouble) { //roll failed- stay in jail
				player.addRoundInJail();
				out.testMessage(translations.get("GAME_STILL_IN_JAIL"));
			}
			if (playerRefusedToRollDouble) { // roll refused - other options
				if (playerHaveEscapeCard) { // have escape card - may use it
					if (GUI.getUserButtonPressed(translations.get("GAME_USE_ESCAPE_CARD"), yesTxt, noTxt) == yesTxt) {
						GUI.showMessage(freeNow);
						player.leaveJailUsingCard();
					} else { // refused to use card - can pay
						if (GUI.getUserButtonPressed(translations.get("GAME_PAY_FINE"), yesTxt, noTxt) == yesTxt) {
							if (!player.haveAmount(50)) {//not enough money - can seel/mortgage or stay in jail
								if (GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_SELL_OR_MORTGAGE"), yesTxt, noTxt) == yesTxt) {
									while(!player.haveAmount(50)) {
										if (player.canSellHouses() || player.canMortgageProperty()) {
											sellOrMortgagePropertyAction(player, board, translations);
										} else {
											player.addRoundInJail();
											out.testMessage(translations.get("GAME_NOTHING_TO_SELL")+" "+translations.get("GAME_STILL_IN_JAIL"));
											break;
										}
									}
								} else {
									player.addRoundInJail();
									out.testMessage(translations.get("GAME_STILL_IN_JAIL"));
								}
							} else {
								player.leaveJailUsingFine();
								GUI.showMessage(freeNow);
							}
						} else {
							player.addRoundInJail();
							out.testMessage(translations.get("GAME_STILL_IN_JAIL"));
						}
					}
				} else { // have no card - can pay 
					if (GUI.getUserButtonPressed(translations.get("GAME_PAY_FINE"), yesTxt, noTxt) == yesTxt) {
						if (!player.haveAmount(50)) {
							if (GUI.getUserButtonPressed(translations.get("GAME_NOT_ENOUGH_MONEY")+" "+translations.get("GAME_DO_YOU_WANT_TO_SELL"), yesTxt, noTxt) == yesTxt) {
								while(!player.haveAmount(50)) {//not enough money - can seel/mortgage or stay in jail
									if (player.canSellHouses() || player.canMortgageProperty()) {
										sellOrMortgagePropertyAction(player, board,translations);
									} else {
										player.addRoundInJail();
										out.testMessage(translations.get("GAME_NOTHING_TO_SELL")+" "+translations.get("GAME_STILL_IN_JAIL"));
										break;
									}
								}
							} else {
								player.addRoundInJail();
								out.testMessage(translations.get("GAME_STILL_IN_JAIL"));
							}
						} else {
							player.leaveJailUsingFine();
							GUI.showMessage(freeNow);
						}
					} else {
						player.addRoundInJail();
						out.testMessage(translations.get("GAME_STILL_IN_JAIL"));
					}
				}
			}
		}
		out.setBalance(player.getName(), player.getAccount());
	}

/**
 * Sell or mortgage
 * @param player
 * @param board
 * @param translations
 */
	private static void sellOrMortgagePropertyAction(Player player, Gameboard board, HashMap<String, String> translations) {
		String[] actions;
		//get actions possible
		//player can sell houses and can mortgage properties
		if (player.canSellHouses() && player.canMortgageProperty()) {
			actions = new String[2];
			actions[0] = translations.get("GAME_SELL_HOUSE");
			actions[1] = translations.get("GAME_MORTGAGE");
		} else if (player.canSellHouses()) { // can only sell houses
			actions = new String[1];
			actions[0] = translations.get("GAME_SELL_HOUSE");
		} else { // can only mortgage
			actions = new String[1];
			actions[0] = translations.get("GAME_MORTGAGE");
		}
		//select action
		if (GUI.getUserButtonPressed(translations.get("GAME_WHAT_TO_DO"), actions) == translations.get("GAME_MORTGAGE")) { //mortgage
			int[] availableToMortgage = player.getPropertiessAvailableToMortgage();
			String[] namesAvToMortgage = new String[availableToMortgage.length];
			int i = 0;
			//get property names
			for (int fieldNr : availableToMortgage) {
				namesAvToMortgage[i] = board.getField(fieldNr).getName();
				i++;
			}
			//select property to mortgage
			String name = GUI.getUserButtonPressed(translations.get("GAME_SELECT_MORTGAGE_PROPERTY"), namesAvToMortgage);
			int nr = board.getFieldNumberByName(name);
			Field field = board.getField(nr);
			int value = field.getMortageValue();
			board.getField(nr).mortgage();
			player.deposit(value);
		} else { //sell house
			int[] availableToSell = player.getHousesAvailableToSell(board);
			String[] namesAvToSell = new String[availableToSell.length];
			int i = 0;
			for (int fieldNr : availableToSell) {
				namesAvToSell[i] = board.getField(fieldNr).getName();
				i++;
			}
			String name = GUI.getUserButtonPressed(translations.get("GAMES_SELECT_SELL_HOUSE"), namesAvToSell);
			int nr = board.getFieldNumberByName(name);
			Field field = board.getField(nr);
			int value = field.getHouseCost();
			board.getField(nr).sellHouse();
			player.deposit(value);
		}
	}
}

	

